package com.woniuxy.auth.mapper;

import com.hc.entity.Role;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.jdbc.SQL;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * @ClassName RoleMapper
 * @Description
 * @Author shanshan
 * @Date 2022/10/23 8:02
 * @Version 1.0
 **/
public interface RoleMapper {
    @Insert("insert into hc_role(name,status) values(#{name},#{status})")
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id") //拿到产生id
    void insert(Role role);

    @Delete("delete from hc_role where id=#{id}")
    void delete(int id);

    @Update("update hc_role set name=#{name},status=#{status} where id=#{id}")
    void update(Role role);

    @Select("select * from hc_role")
    List<Role> getAll();

    @Select("select * from hc_role where id=#{id}")
    @Results(
            {
                    @Result(column = "id",property = "id",id = true),
                    @Result(column = "name",property = "name"),
                    @Result(column = "status",property = "status"),
                    //一对多，此id就是角色Id; select=根据角色Id查询权限列表
                    @Result(column = "id", property = "perms", many = @Many(select = "com.woniuxy.auth.mapper.PermMapper.getByRoleId", fetchType = FetchType.LAZY))
            }
    )
    Role getById(int id);


}
